turf/construct
	var
		mob/owner
		sellval
		HP
		level
	proc/WatchHP()
	New()
		..()
		src.WatchHP()
	verb/Sell()
		if(usr != src.owner)
			usr << "This is not your building to sell!"
			return
		if(alert("Would you really want to sell [src.name]?","Sell?","Yes","No")=="Yes")
			usr.credits += src.sellval
			del src
	verbcache
		ConYard
			verb
				PowPlant()
					set category = "Build MCV"
					set name = "Power Plant MCV"
					if(usr.credits < 500)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new Power Plant.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 500
					var/obj/construct/newbie = new /obj/construct/PowPlant(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
				Finance()
					set category = "Build MCV"
					set name = "Finance Building MCV"
					if(usr.credits < 2000)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new Finance Building.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 2000
					var/obj/construct/newbie = new /obj/construct/Finance(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
				Wall()
					set category = "Build MCV"
					set name = "Wall x5 MCV"
					if(usr.credits < 200)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new Wall MCV.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 200
					var/obj/construct/newbie = new /obj/construct/Wall(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
				Barracks()
					set category = "Build MCV"
					set name = "Barracks MCV"
					if(usr.credits < 1000)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new Barracks.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 1000
					var/obj/construct/newbie = new /obj/construct/Barracks(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
				TechLab()
					set category = "Build MCV"
					set name = "Technology Lab MCV"
					if(usr.credits < 1500)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new Tehnology Lab.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 1500
					var/obj/construct/newbie = new /obj/construct/TechLab(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
				WarFact()
					set category = "Build MCV"
					set name = "War Factory MCV"
					if(usr.credits < 2000)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/ConYard/sources
					for(var/turf/construct/ConYard/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/ConYard/source
					while(!selected)
						source = input("Select a source Construction Yard for a new War Factory.","New Power Plant","Construction Yard (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Construction Yard?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					usr.credits -= 2000
					var/obj/construct/newbie = new /obj/construct/WarFact(loc = locate(source.x + 1,source.y + 1,source.z))
					newbie.owner = usr
					return
		Barracks
			verb
				Foot()
					set category = "Train Barracks Unit"
					set name = "Assault Rifle Soldier"
					if(usr.credits < 200)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/Barracks/sources
					for(var/turf/construct/Barracks/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/Barracks/source
					while(!selected)
						source = input("Select a source Barracks for a new Assault Rifle Soldier.","New Assault Rifle Soldier","Barracks (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Barracks?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/Barracks/newbie
					var/loops = input("How many?","Assault Rifle Soldier",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 200)
							usr << "Not enough credits!"
							return
						usr.credits -= 200
						newbie = new /obj/unit/Barracks/Foot(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
				Engineer()
					set category = "Train Barracks Unit"
					set name = "Engineer"
					if(usr.credits < 500)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/Barracks/sources
					for(var/turf/construct/Barracks/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/Barracks/source
					while(!selected)
						source = input("Select a source Barracks for a new Engineer.","New Engineer","Barracks (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Barracks?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/Barracks/newbie
					var/loops = input("How many?","Engineer",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 500)
							usr << "Not enough credits!"
							return
						usr.credits -= 500
						newbie = new /obj/unit/Barracks/Engineer(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
				Elite()
					set category = "Train Barracks Unit"
					set name = "Elite Soldier"
					if(usr.credits < 1000)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/Barracks/sources
					for(var/turf/construct/Barracks/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/Barracks/source
					while(!selected)
						source = input("Select a source Barracks for a new Elite Soldier.","New Elite Soldier","Barracks (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Barracks?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/Barracks/newbie
					var/loops = input("How many?","Elite Soldier",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 1000)
							usr << "Not enough credits!"
							return
						usr.credits -= 1000
						newbie = new /obj/unit/Barracks/Elite(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
				Rocket()
					set category = "Train Barracks Unit"
					set name = "Rocket Soldier"
					if(usr.credits < 300)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/Barracks/sources
					for(var/turf/construct/Barracks/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/Barracks/source
					while(!selected)
						source = input("Select a source Barracks for a new Rocket Soldier.","New Rocket Soldier","Barracks (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this Barracks?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/Barracks/newbie
					var/loops = input("How many?","Rocket Soldier",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 300)
							usr << "Not enough credits!"
							return
						usr.credits -= 300
						newbie = new /obj/unit/Barracks/Rocket(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
		WarFact
			verb
				ConYard()
					set category = "Construct War Factory Unit"
					set name = "Construction Yard MCV"
					if(usr.credits < 5000)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/WarFact/sources
					for(var/turf/construct/WarFact/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/WarFact/source
					while(!selected)
						source = input("Select a source War Factory for a new Construction Yard.","New Construciton Yard","War Factory (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this War Factory?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/WarFact/newbie
					var/loops = input("How many?","Construction Yard",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 5000)
							usr << "Not enough credits!"
							return
						usr.credits -= 5000
						newbie = new /obj/unit/WarFact/ConYard(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
				Tank()
					set category = "Construct War Factory Unit"
					set name = "Basic Tank"
					if(usr.credits < 750)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/WarFact/sources
					for(var/turf/construct/WarFact/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/WarFact/source
					while(!selected)
						source = input("Select a source War Factory for a new Tank.","New Tank","War Factory (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this War Factory?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/WarFact/newbie
					var/loops = input("How many?","Tank",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 750)
							usr << "Not enough credits!"
							return
						usr.credits -= 750
						newbie = new /obj/unit/WarFact/Tank(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
				ShrapnelTank()
					set category = "Construct War Factory Unit"
					set name = "Shrapnel-firing Tank"
					if(usr.credits < 750)
						usr << "Not enough credits!"
						return
					var/list/turf/construct/WarFact/sources
					for(var/turf/construct/WarFact/chk in world)
						if(chk.owner == usr) sources += chk
					var/selected
					var/turf/construct/WarFact/source
					while(!selected)
						source = input("Select a source War Factory for a new Shrapnel Tank.","New Shrapnel Tank","War Factory (ID:1)") as null|turf in sources
						if(!source) selected = 1
						usr.loc = locate(source)
						if(alert("Use this War Factory?","Check Source","Yes","No") == "Yes") selected = 1
					if(!source) return
					var/obj/unit/WarFact/newbie
					var/loops = input("How many?","Shrapnel Tank",1) as num
					for(var/i = 1,i < loops,i++)
						if(usr.credits < 750)
							usr << "Not enough credits!"
							return
						usr.credits -= 750
						newbie = new /obj/unit/WarFact/ShrapnelTank(loc = locate(source.x + 1,source.y + 1,source.z))
						newbie.owner = usr
					return
	ConYard //5000 credits
		name = "Construction Yard"
		sellval = 2500
		New()
			..()
			owner.controlobj++
			owner.ConYards++
			name = "Construction Yard (ID:[owner.ConYards])"
		Del()
			owner.controlobj--
			..()
	PowPlant //500 credits
		name = "Power Plant"
		sellval = 250
		New()
			..()
			owner.controlobj++
			owner.techexp += 5
			owner.availpower += 40
		verb/Upgrade()
			set desc = "Increase the power output of this building."
			if(usr != src.owner)
				usr << "This is not your building to upgrade!"
				return
			if((src.level + 1)*250 > usr.credits)
				usr << "You don't have enough credits to do that."
				return
			usr.credits -= (src.level + 1)*250
			src.sellval += ((src.level + 1)*250)/2
			usr.availpower += 40
			src.level++
		Del()
			owner.controlobj--
			owner.availpower -= src.level * 40
			owner.techexp -= 5
			..()
	Finance //2000 credits
		name = "Finance Building"
		sellval = 1000
		New()
			..()
			owner.controlobj++
			owner.income += 50
			owner.availpower -= 10
		verb/Upgrade()
			set desc = "Increase the income of this building."
			if(usr != src.owner)
				usr << "This is not your building to upgrade!"
				return
			if((src.level + 1)*1000 > usr.credits)
				usr << "You don't have enough credits to do that."
				return
			usr.credits -= (src.level + 1)*1000
			src.sellval += ((src.level + 1)*1000)/2
			usr.income += 50
			src.level++
		Del()
			owner.controlobj--
			owner.income -= src.level * 50
			owner.availpower += 10
			..()
	Wall //200 credits for 5
		name = "Wall"
		Sell()
			usr << "This building cannot be sold."
			return
	Barracks //1000 credits
		name = "Barracks"
		sellval = 500
		New()
			..()
			owner.controlobj++
			owner.availpower -= 5
			owner.Barracks++
			name = "Barracks (ID:[owner.Barracks])"
		Del()
			owner.controlobj--
			owner.availpower += 5
			..()
	WarFact //2000 credits
		name = "War Factory"
		sellval = 1000
		New()
			..()
			owner.controlobj++
			owner.availpower -= 20
			owner.WarFacts++
			name = "War Factory (ID:[owner.WarFacts])"
		Del()
			owner.controlobj--
			owner.availpower += 20
			..()
	TechLab //1500 credits
		name = "Technology Lab"
		sellval = 750
		New()
			..()
			owner.controlobj++
			owner.techexp += 25
			owner.availpower -= 15
		verb/Upgrade()
			set desc = "Increase the Technology Experience from this building."
			if(usr != src.owner)
				usr << "This is not your building to upgrade!"
				return
			if((src.level + 1)*750 > usr.credits)
				usr << "You don't have enough credits to do that."
				return
			usr.credits -= (src.level + 1)*750
			src.sellval += ((src.level + 1)*750)/2
			usr.techexp += 25
			src.level++
		Del()
			owner.controlobj--
			owner.techexp -= src.level*25
			owner.availpower += 15
			..()